Skip to main content

olem module

The olem module gives access to all the features of OLEM: movements, LEDs, sensors, display, game messages... Import it at the top of your game with import olem.

Generated from version ad8133d of the game development kit.

Movement​

Constants​

ConstantValueDescription
MOVE_CORR_X_MASK1Correction along the x axis, based on the lines of the tiles.
MOVE_CORR_Y_MASK2Correction along the y axis, based on the lines of the tiles.
MOVE_CORR_DISTANCE_MASK4Correction of the travelled distance, based on the spacing between the lines of the tiles. Requires MOVE_CORR_X_MASK.
MOVE_CORR_IWJ_MASK32
MOVE_CORR_ISS_MASK64
MOVE_CORR_MSAFE_MASK128Refuse movements that would make OLEM fall off the board or table.

move(x, y, rotation)​

Move OLEM by the requested amount in cartesian space, relative to its current position.

Returns immediately, use wait_stop_moving() to wait for the end of the movement.

ParameterDescription
xtranslation along the x axis in mm
ytranslation along the y axis in mm
rotationrotation in degrees

move_to(x, y, orientation)​

Move OLEM to a position in cartesian space, relative to its position at startup or at the last reset_position().

Returns immediately, use wait_stop_moving() to wait for the end of the movement.

ParameterDescription
xposition along the x axis in mm
yposition along the y axis in mm
orientationorientation in degrees

wait_stop_moving()​

Block until OLEM stops moving.

The wait ends if the game is stopped.

stop_moving()​

Stop the current movement.

turn(rotation)​

Turn OLEM on itself by the requested angle.

Returns immediately, use wait_stop_moving() to wait for the end of the rotation.

ParameterDescription
rotationrotation in degrees

turn_to(orientation)​

Turn OLEM on itself to the requested orientation.

Returns immediately, use wait_stop_moving() to wait for the end of the rotation.

ParameterDescription
orientationorientation in degrees

move_polar(distance, direction, rotation)​

Move OLEM by the requested amount in polar space, relative to its current position.

Returns immediately, use wait_stop_moving() to wait for the end of the movement.

ParameterDescription
distancedistance to travel in mm
directiondirection of the movement in degrees
rotationrotation in degrees

move_to_polar(distance, direction, orientation)​

Move OLEM to a position given in polar space, relative to its position at startup or at the last reset_position().

Returns immediately, use wait_stop_moving() to wait for the end of the movement.

ParameterDescription
distancedistance from the origin in mm
directiondirection from the origin in degrees
orientationorientation in degrees

move_towards(direction)​

Move OLEM in a direction until stop_moving() is called.

ParameterDescription
directiondirection in degrees, relative to OLEM's current orientation

set_move_speed(speed)​

Set the speed of the movements requested after this call.

The default speed is 1.0.

ParameterDescription
speedfraction of the maximum speed, from 0.0 to 1.0

get_move_speed()​

Returns: speed set with set_move_speed(), from 0.0 to 1.0

get_position_x()​

Returns: position along the x axis in mm, relative to the position at startup or at the last reset_position()

get_position_y()​

Returns: position along the y axis in mm, relative to the position at startup or at the last reset_position()

get_orientation()​

Returns: orientation in degrees, from 0 to 359

get_orientation_absolute()​

Unlike get_orientation(), the orientation is not brought back between 0 and 359: it keeps counting full turns and can be above 360 or negative.

Returns: orientation in degrees, as an integer

reset_position()​

Stop the current movement and use the current position as the new origin: position (0, 0) and orientation 0.

is_moving()​

Returns: True if OLEM is moving, False otherwise

center_on_rotate(angle)​

Re-center OLEM on its tile: OLEM turns on itself and uses the lines of the tile seen by its floor sensors to correct its position.

Returns immediately. Has no effect if a centering is already running.

ParameterDescription
anglerotation to perform in degrees, 90 is recommended

move_correction_enable(mask)​

Enable automatic corrections of the movements.

ParameterDescription
maskcorrections to enable, combine MOVE_CORR_* constants with |

move_correction_disable(mask)​

Disable automatic corrections of the movements.

ParameterDescription
maskcorrections to disable, combine MOVE_CORR_* constants with |

Extension module​

Constants​

ConstantValueDescription
LOW0Low level of a GPIO output.
HIGH1High level of a GPIO output.
EXTMOD_GPIO11Pin P1 of the extension slots.
EXTMOD_GPIO22Pin P2 of the extension slots.
EXTMOD_GPIO0GPIO mode: P1 and P2 are digital outputs.
EXTMOD_I2C1I2C mode: P1 is SCL and P2 is SDA.
EXTMOD_PWM2PWM mode: P1 and P2 output PWM signals.

extmod_mode_set(mode)​

Initialize the extension slots in the given mode. Only one mode can be used at a time.

ParameterDescription
modeEXTMOD_GPIO, EXTMOD_I2C or EXTMOD_PWM

extmod_gpio_set(gpio, value)​

Set the output level of a pin. Requires the EXTMOD_GPIO mode, see extmod_mode_set().

ParameterDescription
gpioEXTMOD_GPIO1 or EXTMOD_GPIO2
valueLOW or HIGH

extmod_pwm_set(gpio, period, compare_value)​

Set the PWM signal of a pin. Requires the EXTMOD_PWM mode, see extmod_mode_set().

ParameterDescription
gpioEXTMOD_GPIO1 or EXTMOD_GPIO2
periodperiod of the signal in ms, as an integer. With 0 the output stays LOW.
compare_valuetime the signal stays HIGH in each period in ms, as an integer

extmod_i2c_read(addr, length)​

Read bytes from a device on the I2C bus. Requires the EXTMOD_I2C mode, see extmod_mode_set().

ParameterDescription
addraddress of the device
lengthnumber of bytes to read

Returns: list of the bytes read, as integers, or an empty list if the read failed

extmod_i2c_write(addr, data)​

Write bytes to a device on the I2C bus. Requires the EXTMOD_I2C mode, see extmod_mode_set().

ParameterDescription
addraddress of the device
datalist of the bytes to write, as integers from 0 to 255

Returns: 0 on success, an error code otherwise

LEDs​

Constants​

ConstantValueDescription
LED01Mask of LED 0.
LED12Mask of LED 1.
LED24Mask of LED 2.
LED38Mask of LED 3.
LED416Mask of LED 4.
LED532Mask of LED 5.
LEDALL63Mask of all the LEDs.

led_on(mask, hexcolor)​

Turn LEDs on with a fixed color.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
hexcolorcolor as a "#RRGGBB" string

led_off(mask)​

Turn LEDs off.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL

led_pulse(mask, period, hexcolor)​

Make LEDs pulse: they fade smoothly in and out of the color.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
periodpulse period in ms
hexcolorcolor as a "#RRGGBB" string

Make LEDs blink: they switch between the color and off.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
periodblink period in ms
hexcolorcolor as a "#RRGGBB" string

led_transition(mask, duration, hexcolor)​

Change the color of LEDs smoothly, from their current color to the new one.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
durationduration of the transition in ms
hexcolornew color as a "#RRGGBB" string

led_flicker(mask, intensity)​

Add random noise to the color of LEDs, on top of their current effect: it can be used while LEDs are pulsing for example.

At each refresh, a random value of up to +/- half of the intensity is added to each color component. For example led_flicker(LEDALL, "#100020") adds up to +/- 8 to the red and up to +/- 16 to the blue of all the LEDs.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
intensitynoise intensity of each component as a "#RRGGBB" string

led_flicker_off(mask)​

Stop the noise added with led_flicker().

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL

led_shifting(period, direction)​

Periodically move the configuration of each LED to its neighbour, so that the LED pattern turns around OLEM.

ParameterDescription
periodtime between two shifts in ms
direction0 to shift from left to right, 1 from right to left

led_shifting_off()​

Stop the shifting started with led_shifting().

Timing​

delay_ms(delay)​

Wait for the given duration. The game can still be stopped during the wait.

ParameterDescription
delayduration in ms

get_time_ms()​

Returns: time since OLEM started in ms

Side sensors​

Constants​

ConstantValueDescription
FRONT0Front side of OLEM.
RIGHT1Right side of OLEM.
BACK2Back side of OLEM.
LEFT3Left side of OLEM.
FRONT_MASK1Bit of the front side in a side mask.
RIGHT_MASK2Bit of the right side in a side mask.
BACK_MASK4Bit of the back side in a side mask.
LEFT_MASK8Bit of the left side in a side mask.

ir_side_get_sensor_value(sensor)​

Get the signal of a side sensor. Side sensors see objects up to about 150 mm away.

ParameterDescription
sensorFRONT, RIGHT, BACK or LEFT

Returns: filtered signal in ADC units (LSB), it increases when an object gets closer

ir_side_get_sensor_percent(sensor)​

Get the signal of a side sensor as a percentage.

ParameterDescription
sensorFRONT, RIGHT, BACK or LEFT

Returns: from 0 when nothing is detected to 100 when an object is very close

ir_side_is_hand_present(side)​

Check if a hand is in front of a side sensor. A hand gives a weaker signal than an obstacle.

ParameterDescription
sideFRONT, RIGHT, BACK or LEFT

Returns: True if a hand is detected, False otherwise or if side is not valid

ir_side_is_obstacle_present(side)​

Check if an obstacle is in front of a side sensor. An obstacle gives a stronger signal than a hand.

ParameterDescription
sideFRONT, RIGHT, BACK or LEFT

Returns: True if an obstacle is detected, False otherwise or if side is not valid

ir_side_get_hand_mask()​

Returns: mask with the bit of each side where a hand is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK

ir_side_get_obstacle_mask()​

Returns: mask with the bit of each side where an obstacle is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK

ir_side_get_number_of_hands()​

Returns: number of sides where a hand is detected, from 0 to 4

ir_side_set_filter(value)​

Set the filter applied to the side sensors. A higher value makes them slower to react but more stable. The default value is 5.

ParameterDescription
valuefilter coefficient, 1 or more

Floor sensors​

ir_floor_get_sensor_value(sensor)​

Get the signal of a floor sensor. The signal is the strongest on a white surface and the weakest on a black surface or when there is no floor.

OLEM has 6 floor sensors, numbered clockwise: 0 front left, 1 front right, 2 right, 3 back right, 4 back left, 5 left.

ParameterDescription
sensorindex of the sensor, from 0 to 5

Returns: signal in ADC units (LSB), or 0 if sensor is not valid

ir_floor_is_floor_present(side)​

Check if there is floor under a side of OLEM, to detect the edge of the board or table.

ParameterDescription
sideFRONT, RIGHT, BACK or LEFT

Returns: True if the floor is detected, False otherwise or if side is not valid

ir_floor_get_void_count()​

Returns: number of floor sensors that do not see the floor

Top sensor​

ir_top_is_hand_present()​

Check if a hand is above the top sensor. It can be used as a button for the players.

Returns: True if a hand is detected, False otherwise

ir_top_get_sensor_value()​

Returns: filtered signal of the top sensor in ADC units (LSB), it increases when a hand gets closer

ir_top_get_sensor_percent()​

Returns: signal of the top sensor, from 0 when nothing is detected to 100 when a hand is very close

Game messenger​

gmsg_wait_for_message()​

Wait for a message from the mobile app or the Command Center. The game can still be stopped during the wait.

Received messages are kept in a queue of up to 20 messages.

Returns: the oldest message received

gmsg_wait_for_message_timeout(timeout)​

Wait for a message from the mobile app or the Command Center, for a limited time.

ParameterDescription
timeoutmaximum time to wait in ms

Returns: the oldest message received, or an empty string if no message arrived in time

gmsg_send_message(message)​

Send a message to the mobile app or the Command Center.

ParameterDescription
messagetext of up to 100 bytes. Do not use the alert character "\a".

gmsg_reset_queue()​

Delete the received messages that were not read yet.

gmsg_get_message()​

Get the oldest received message, without waiting.

Returns: the oldest message received, or an empty string if there is none

gmsg_get_waiting_message_count()​

Returns: number of received messages that were not read yet

Display​

Constants​

ConstantValueDescription
FONT_DEFAULT0Default font size.
FONT_SMALL1Small font size.
FONT_BIG2Big font size.
ALIGN_LEFT0Text aligned on the left.
ALIGN_CENTER1Text centered.
ALIGN_RIGHT2Text aligned on the right.

class lv_obj​

Type of the screen objects returned by the display functions, such as display_text() or display_button(). It cannot be created directly.

The screen is 320 x 240 px, (0, 0) is its top left corner.

display_text(text, font_size, align)​

Create a text object.

ParameterDescription
texttext to display
font_sizeFONT_SMALL, FONT_DEFAULT or FONT_BIG
alignALIGN_LEFT, ALIGN_CENTER or ALIGN_RIGHT

Returns: the text object

display_button(text, event_id)​

Create a button. When it is pressed, event_id is added to the event queue, see display_get_event().

ParameterDescription
texttext of the button
event_idinteger identifying the button in the event queue, 0 is not allowed

Returns: the button object

display_img(file_name)​

Create an image object from a file. Images must be converted with the LVGL v8 image converter, in binary RGB565.

ParameterDescription
file_namepath of the image file, relative to the assets folder of the game

Returns: the image object

display_img_button(file_name)​

Create a clickable image object from a file. Use display_add_event_cb() to choose the event it triggers.

ParameterDescription
file_namepath of the image file, relative to the assets folder of the game

Returns: the image object

display_qr_code(size, data)​

Create a QR code object, black on white.

ParameterDescription
sizewidth and height in px
datatext encoded in the QR code

Returns: the QR code object

display_set_qr_code_data(lvgl_obj, data)​

Change the text encoded in a QR code object.

ParameterDescription
lvgl_objQR code object created with display_qr_code()
datanew text to encode

display_add_event_cb(lvgl_obj, event_id)​

Make an object clickable: when it is clicked, event_id is added to the event queue, see display_get_event().

ParameterDescription
lvgl_objobject to make clickable
event_idinteger identifying the object in the event queue, 0 is not allowed

display_del(lvgl_obj)​

Delete an object from the screen. It must not be used afterwards.

ParameterDescription
lvgl_objobject to delete

display_del_all()​

Delete all the objects from the screen. The background color is kept.

display_center(lvgl_obj)​

Center an object on the screen.

ParameterDescription
lvgl_objobject to center

display_set_pos(lvgl_obj, x, y)​

Move an object on the screen.

ParameterDescription
lvgl_objobject to move
xposition of its left side in px
yposition of its top side in px

display_get_pos(lvgl_obj)​

ParameterDescription
lvgl_objdisplayed object

Returns: position of the object as a list [x, y] in px

display_get_size(lvgl_obj)​

The object must already be drawn on screen, see display_wait_for_next_frame().

ParameterDescription
lvgl_objdisplayed object

Returns: size of the object as a list [width, height] in px

display_set_size(lvgl_obj, width, height)​

Resize an object. Images are not scaled, only their container is resized.

ParameterDescription
lvgl_objobject to resize
widthnew width in px
heightnew height in px

display_set_text(lvgl_obj, text)​

Change the text of a text object.

ParameterDescription
lvgl_objtext object created with display_text()
textnew text to display

display_set_img_src(lvgl_obj, file_name)​

Change the image of an image object.

ParameterDescription
lvgl_objimage object created with display_img()
file_namepath of the new image file, relative to the assets folder of the game

display_move_to_foreground(lvgl_obj)​

Draw an object above all the others.

ParameterDescription
lvgl_objobject to move

display_move_to_layer(lvgl_obj, index)​

Choose in which order an object is drawn.

ParameterDescription
lvgl_objobject to move
index0 is the background, the foreground is the number of objects on screen minus 1

display_wait_for_next_frame()​

Wait until the next frame is drawn on screen.

display_mutex_take()​

Prevent the screen from being redrawn, so that several objects can be created and configured before they appear. The screen is frozen until display_mutex_give() is called.

display_mutex_give()​

Allow the screen to be redrawn again after display_mutex_take().

display_get_event()​

Get the oldest event triggered by a button or a clickable object, without waiting.

Returns: id of the oldest event, or 0 if there is none

display_clear_events()​

Delete the events that were not read yet.

display_wait_for_event()​

Wait for an event triggered by a button or a clickable object. The game can still be stopped during the wait.

Returns: id of the event

display_wait_for_event_timeout(timeout)​

Wait for an event triggered by a button or a clickable object, for a limited time.

ParameterDescription
timeoutmaximum time to wait in ms

Returns: id of the event, or 0 if no event happened in time

display_set_bkg_color(color)​

Change the background color of the screen.

ParameterDescription
colorcolor as a "#RRGGBB" string

display_set_text_color(lvgl_obj, color)​

Change the color of a text object.

ParameterDescription
lvgl_objtext object created with display_text()
colorcolor as a "#RRGGBB" string

display_set_default_text_color(color)​

Change the color of the text objects created after this call.

ParameterDescription
colorcolor as a "#RRGGBB" string

display_set_backlight(value)​

Set the brightness of the screen.

ParameterDescription
valuebrightness from 0 to 100, other values are clamped

Audio​

audio_play_file(file_name)​

Play an audio file. The sound being played, if any, is stopped. Returns immediately, see audio_wait_end_of_playback().

ParameterDescription
file_namepath of the audio file, relative to the assets folder of the game

audio_is_playing()​

Returns: True if a sound is being played, False otherwise

audio_wait_end_of_playback()​

Wait for the end of the sound being played. Returns immediately if no sound is played. The game can still be stopped during the wait.

audio_stop()​

Stop the sound being played.

audio_pause()​

Pause the sound being played, see audio_resume().

audio_resume()​

Resume the sound paused with audio_pause().

audio_mute(mute)​

Mute or unmute the sound.

ParameterDescription
muteTrue to mute, False to unmute

audio_volume_set(volume)​

Set the volume of the game sounds. The volume chosen in OLEM's settings still applies on top of it.

ParameterDescription
volumefrom 0.0 (muted) to 1.0 (maximum)

audio_volume_get()​

Returns: volume set with audio_volume_set(), from 0.0 to 1.0

audio_volume_enable(enable)​

Enable or disable the volume set with audio_volume_set().

ParameterDescription
enableTrue to enable, False to disable

audio_white_noise_enable(enable)​

Start or stop playing white noise.

ParameterDescription
enableTrue to start, False to stop

audio_white_noise_amplitude_set(amplitude)​

Set the loudness of the white noise.

ParameterDescription
amplitudefrom 0.0 to 1.0, fraction of the maximum amplitude

audio_white_noise_amplitude_get()​

Returns: amplitude set with audio_white_noise_amplitude_set(), from 0.0 to 1.0

NFC​

nfc_enable()​

Start detecting NFC tags. The reader is under OLEM, between the front wheels. Only NTAG type 2 tags (ISO/IEC 14443A, sold as NTAG2xx) are supported.

nfc_disable()​

Stop detecting NFC tags.

nfc_is_enabled()​

Returns: True if NFC detection is enabled, False otherwise

nfc_get_number_of_cards_waiting()​

Returns: number of detected tags that were not read yet with nfc_get_card_data()

nfc_get_card_data()​

Get the data of the oldest detected tag that was not read yet.

Returns: text stored on the tag, or an empty string if there is no tag waiting

System​

get_sys_language()​

Returns: language chosen in OLEM's settings: "EN" for English, "FR" for French

get_power_button_state()​

Returns: 0 while the power button is pressed, 1 otherwise